<?php
class SysAction extends BaseAction{
	function _initialize(){
		parent::_initialize();
		$this->dao=M("SystemConfig");
		$platform=$this->dao->field('value,title')->where('element="platform" AND platform="SYS"')->select();
		$platform=field2key($platform, 'value');
		$platform['SYS']=array('title'=>'系统','value'=>'SYS');
		$this->assign('sysplatform',$platform);
	}
	
	function _after_insert(){
		//更新缓存
		parent::_cache(1,'sys');
	}
	function _after_update(){
		//更新缓存
		parent::_cache(1,'sys');
	}
	
	/**
	 *查看系统设置
	 *@date 2013-12-16
	 *@time 下午3:42:38
	 */
	function detail() {
	//查看系统设置
	}//end detail
	
	//幻灯片列表
	function banner(){
		$where = array();
		if($this->keywords){
			$sfield_name = $_REQUEST['sfield_name'];
			$where[$sfield_name] = array('LIKE','%'.$this->keywords.'%');
		}
		$dao = M("SlideData");	
		$count = $dao->where($where)->count();
		$this->assign("totalCount",$count);
		if($count){
			$page=new Page($count,$this->listrows);
			$res = $dao->join(' as sd left join slide as s on s.id = sd.fid ')
			->where($where)->field('sd.* ,s.name')
			->order('status desc ,fid')
			->limit($page->firstRow.','.$page->listRows)->select();
			$this->assign('list',$res);
		}		
		$this->display();		
	}
	
	//幻灯片添加
	function banner_add(){
		$dao = M("Slide");		
		$res = $dao->where('status=1')->select();
		
		$dao = M("SlideData");
		$id = $_GET['id'];
		if($id){
			$slidesdata = $dao->select($id);
			$this->assign('slidesdata',$slidesdata);
		}
		$this->assign('slides',$res);
		$this->display();
	}
	
	//幻灯片保存 
	function  banner_insert(){
		$dao = M("SlideData");
		$data['fid'] = $_REQUEST['fid'];
		$data['status'] = 1;
		$pics = $_REQUEST['pics'];
		$title = $_REQUEST['title'];
		$link = $_REQUEST['link'];
		foreach ($pics as $key=>$pic){
			$data['pic'] = $pic;
			$data['title'] = $title[$key];
			$data['link'] = $link[$key];
			$reid = $dao->add($data);
		}
		if($reid>0){
			$this->_ajm(200,'添加成功');
		}
	}
	
	//删除幻灯片
	function banner_del(){
		$id = $_GET['id'];
		if(!$id){
			$this->_ajm(300,'选择商品错误！',1);
		}
		$dao = M("SlideData");
		$reid = $dao->delete($id);
		if($reid>0){
			$this->_ajm(200,'删除成功！',1);
		}else {
			$this->_ajm(300,'删除失败！',1);
		}
	}
		
}
